/**
 * chenuu.com
 * 
 * @author  zhaoxu.com@gmail.com
 * @created 2012-11-3
 */
package com.chenuu.integration.httpclient.utils;

import java.util.HashMap;
import java.util.Map;

import com.chenuu.common.exceptions.ChenuuException;

/**
 *
 */
public class ResponseUtil {

	private static final int INDEX_NAME = 0;
	private static final int INDEX_VALUE = 1;

	private static final String SPLIT_RES_PAIR = "&";
	private static final String SPLIT_NAME_VALUE = "=";

	public static Map<String, String> getResponseMap(String response) {

		if (response == null) {
			throw new ChenuuException("参数[response]不能为空。");
		}

		String[] responsePairs = response.split(SPLIT_RES_PAIR);

		Map<String, String> responseMap = new HashMap<String, String>();
		for (String responsePair : responsePairs) {
			String[] nv = responsePair.split(SPLIT_NAME_VALUE);
			responseMap.put(nv[INDEX_NAME], nv[INDEX_VALUE]);
		}

		return responseMap;
	}
}
